package fun.wlfj.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import fun.wlfj.dao.ILogDao;
import fun.wlfj.dbc.IConnectionManager;
import fun.wlfj.dbc.MySQLConnection;
import fun.wlfj.vo.Log;

public class LogDaoImpl extends AbsDaoImpl implements ILogDao {
	
	public LogDaoImpl(Connection conn) {
		super(conn);
	}

	@Override
	public List<Log> getLogs() {
		List<Log> list = new LinkedList<Log>();
		PreparedStatement pstsm = null;
		try {
			pstsm = conn.prepareStatement("select * from logs;");
			ResultSet rs = pstsm.executeQuery();
			while(rs.next()) {
				list.add(new Log(rs.getInt(1), rs.getString(2), rs.getDate(3)));
			}
			IConnectionManager.closePstsm(pstsm);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public static void main(String[] args) {
		IConnectionManager manager = new MySQLConnection();
		LogDaoImpl testdao = new LogDaoImpl(manager.getConn());
		List<Log> logList = testdao.getLogs();
		System.err.println("测试Log功能");
		for(Log l : logList) {
			System.out.println(l);
		}
		manager.closeAll(null);
	}
}
